﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UniMana.Data;
using System.Data.Linq;
using UniMana.Utils.Helper;
using UniMana.Utils.Configs;
namespace UniMana.Data
{
    public static class Personnel_ContactWorkDaysData
    {
        #region [Hữu]
        /// <summary>
        /// Lấy danh sách ngày hợp đồng lao động theo đơn vị
        /// </summary>
        /// <param name="workday"></param>
        /// <param name="m_data"></param>
        /// <param name="deptKey">Mã đơn vị</param>
        /// <returns></returns>
        public static IQueryable GetPersonelContactWorkDays(this Table<Personnel_ContactWorkDay> workday, DBMain m_data, int deptKey=-1)
        {
            var q = from ps in m_data.m_DCReadOnly.Personnel_Personnels
                    join wd in workday
                    on ps.Personnel_PersonnelKey equals wd.Personnel_PersonnelKey
                    into LeftJoin
                    from lj in LeftJoin.DefaultIfEmpty()
                    where ps.Catalogue_DepartmentKey == deptKey && ps.Personnel_PersonnelTypeKey!=2
                    select new
                    {
                        ps.Personnel_PersonnelKey,
                        ps.LastName,
                        ps.Name,
                        ContactWorkDays  = lj.ContactWorkDays==null?0:lj.ContactWorkDays
                    };
            return q;
        }
        #endregion
    }
}
